import axios from "axios";
// import { pinia } from 'pinia'
// import { ElMessage } from "element-plus";
// import { useCoolStore, useRouterCool } from "@/cool";

let instance = axios.create({
  timeout: import.meta.env.VITE_TIMEOUT,
  baseURL: import.meta.env.VITE_API_URL,
});
instance.interceptors.request.use(
  function (config) {
    return config;
  },
  function (error) {
    return Promise.reject(error);
  }
);

//添加一个响应拦截器
instance.interceptors.response.use(
  function (response) {
    if (response.status === 200 || response.status === 201) {
      return Promise.resolve(response);
    } else {
      return Promise.reject(response);
    }
  },
  function (error) {
    return Promise.reject(error.response);
  }
);

export default instance;
